package cn.edu.sgu.www.mhxysy.controller.jingmai;

import cn.edu.sgu.www.mhxysy.consts.CustomConstants;
import cn.edu.sgu.www.mhxysy.consts.CustomMessages;
import cn.edu.sgu.www.mhxysy.consts.MimeTypes;
import cn.edu.sgu.www.mhxysy.dto.jingmai.StarStoneDTO;
import cn.edu.sgu.www.mhxysy.entity.jingmai.StarStone;
import cn.edu.sgu.www.mhxysy.pager.jingmai.StarStonePager;
import cn.edu.sgu.www.mhxysy.restful.JsonPage;
import cn.edu.sgu.www.mhxysy.restful.JsonResult;
import cn.edu.sgu.www.mhxysy.service.jingmai.StarStoneService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;

/**
 * @author 沐雨橙风ιε
 * @version 1.0
 */
@Api(tags = "星辰晶石管理")
@ApiSupport(author = CustomConstants.AUTHOR)
@Validated
@RestController
@RequestMapping(path = "/star_stone", produces = MimeTypes.APPLICATION_JSON_CHARSET_UTF_8)
public class StarStoneController {
    
    private final StarStoneService starStoneService;

    @Autowired
    public StarStoneController(StarStoneService starStoneService) {
        this.starStoneService = starStoneService;
    }

    @ApiOperation("添加星辰晶石")
    @ApiOperationSupport(ignoreParameters = "id")
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public JsonResult<Void> insert(@Validated StarStoneDTO starStoneDTO) {
        starStoneService.insert(starStoneDTO);

        return JsonResult.success(CustomMessages.INSERT_SUCCESS);
    }

    @ApiOperation("通过ID删除星辰晶石")
    @RequestMapping(value = "/deleteById", method = RequestMethod.POST)
    public JsonResult<Void> deleteById(
            @ApiParam(name = "id", value = "星辰晶石ID", required = true)
            @NotBlank(message = CustomMessages.ID_NOT_NULL) String id) {
        starStoneService.deleteById(id);

        return JsonResult.success(CustomMessages.DELETE_SUCCESS);
    }

    @ApiOperation("通过ID修改星辰晶石")
    @RequestMapping(value = "/updateById", method = RequestMethod.POST)
    public JsonResult<Void> updateById(@Validated StarStoneDTO starStoneDTO) {
        starStoneService.updateById(starStoneDTO);

        return JsonResult.success(CustomMessages.UPDATE_SUCCESS);
    }

    @ApiOperation("分页查询星辰晶石列表")
    @RequestMapping(value = "/selectByPage", method = RequestMethod.POST)
    public JsonResult<JsonPage<StarStone>> selectByPage(StarStonePager pager) {
        Page<StarStone> page = starStoneService.selectByPage(pager);

        return JsonResult.restPage(page);
    }

}